<template>
  <div>
    <el-form :inline="true" class="demo-form-inline">
        <el-row>
            <p><b>首页</b>/住院部/入院申请表</p>
        </el-row>
<br>
        <el-row>
            <el-col :span="3">  
            <el-form-item>
                <el-select placeholder="请选择医生" v-model="param.staffId">
                <el-option :label="inpatientStaff.wkName" :key="inpatientStaff.id" :value="inpatientStaff.id" v-for="inpatientStaff in inpatientStaffList"></el-option>
                </el-select>
            </el-form-item>
            </el-col> 

            <el-col :span="3">
                <el-form-item>
                <el-input placeholder="请输入病人" v-model="param.patientName"></el-input>
                </el-form-item>
            </el-col>

            <el-col :span="3">
                <el-form-item>
                <el-select placeholder="请选择科室" v-model="param.departmentId">
                <el-option :label="inpatientDepartment.deName" :key="inpatientDepartment.id" :value="inpatientDepartment.id" v-for="inpatientDepartment in inpatientDepartmentList"></el-option>
                </el-select>
                </el-form-item>
            </el-col>

            <el-col :span="4">
                <el-form-item>
                    <el-radio v-model="param.radio" label=1>待确定</el-radio>
                    <el-radio v-model="param.radio" label=2>已办理入院</el-radio>
                </el-form-item>
            </el-col>

            <el-col :span="4">
                <el-form-item>
                    <el-date-picker
                    v-model="valuedate"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        value-format="yyyy-MM-dd">
                    </el-date-picker>
                </el-form-item>
            </el-col>

            <el-col :span="3" :offset="2">
                <el-form-item>
                    <el-button type="primary" @click="queryInpatientRequestBtn">查询</el-button>
                    <el-button @click="resetForm">清空</el-button>
                  </el-form-item>
            </el-col>
        </el-row> 
    </el-form>

    <el-row>
        <el-table
            :data="tableData"
            style="width: 100%"
            >
            <el-table-column
            fixed
            prop="patientAllName"
            label="病人"
            >
            </el-table-column>
            <el-table-column
            prop="departmentName"
            label="住院科室"
            >
            </el-table-column>
            <el-table-column
            prop="staffName"
            label="申请医师"
            >
            </el-table-column>
            <el-table-column
            prop="requestTime"
            label="申请日期"
            >
            </el-table-column>
           
            <el-table-column
            fixed="right"
            label="操作"
            >
            <template slot-scope="scope">
                
                <el-button v-if="scope.row.status==0" type="danger" :disabled="scope.row.status=='1' ? false:true">
                未缴费
                </el-button>
                <el-button v-if="scope.row.status==1" type="success" :disabled="scope.row.status=='1' ? false:true" @click="goInHospitalBtn(scope.row.rrId,scope.row.hrId)">
                办理入院
                </el-button>
                <el-button v-if="scope.row.status==2" type="info" :disabled="scope.row.status=='1' ? false:true">
                已办理入院
                </el-button>
            </template>
            </el-table-column>
        </el-table>
    </el-row>

    <el-row>
      <el-col>
        <el-pagination
                background
                :page-sizes="[3, 5, 10, 30]"
                :page-size="pageSize"
                :current-page="pageNum"
                layout="prev, pager, next, total, sizes"
                :total="total"
                @next-click="nextPage"
                @prev-click="prevPage"
                @current-change="changePage"
                @size-change="changeSize"
                >
        </el-pagination>
      </el-col>
    </el-row>

  
    <el-dialog title="办理入院" :visible.sync="goInHospitalForm" width="700px">
      <el-form>
        <el-form-item label="住院部医生">
          <el-select  placeholder="请选择医生:" v-model="inpatientInfo.workId">
            <el-option :label="inpatientStaff.wkName" :key="inpatientStaff.id" :value="inpatientStaff.id" v-for="inpatientStaff in inpatientStaffList"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="住院部床位">
          <el-select  placeholder="请选择床位:" v-model="inpatientInfo.bedId">
            <el-option :label="bed.bno" :key="bed.id" :value="bed.id" v-for="bed in allBedList"></el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="goInHospitalForm = false">取 消</el-button>
        <el-button type="primary" @click="saveGoInHospital">确 定</el-button>
      </div>
    </el-dialog>
</div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
        tableData: [{
        }],

        inpatientStaffList:[],
        inpatientDepartmentList:[],
        allBedList:[],
        param:{
          radio:""
        },
        valuedate:'',
        pageSize:5,
        pageNum:1,
        total:0,
        goInHospitalForm:false,
        inpatientInfo:{
            
        },

    }
  },

  methods: {
    queryInpatientStaff(){
      this.$axios.get("api/request/queryInpatientStaff").then(resp=>{
        if(resp.data.code==200){
          this.inpatientStaffList=resp.data.data
        }
      })
    },

    queryInpatientDepartment(){
      this.$axios.get("api/request/queryInpatientDepartment").then(resp=>{
        if(resp.data.code==200){
          this.inpatientDepartmentList=resp.data.data
        }
      })
    },

    queryAllBed(){
      this.$axios.get("api/request/queryAllBed").then(resp=>{
        if(resp.data.code==200){
          // console.log(resp.data)
          this.allBedList=resp.data.data
        }
      })
    },

    queryInpatientRequestBtn(){
      this.param.startTime=this.valuedate[0]
      this.param.endTime=this.valuedate[1]
      let pageData={}
      pageData.pageSize=this.pageSize
      pageData.pageNum=this.pageNum
      pageData.param=this.param
      this.$axios.post('api/request/queryInpatientRequestBtn',pageData).then(resp=>{
        if(resp.data.code==200){
          
          this.tableData=resp.data.data.list
          this.total=resp.data.data.total
          // console.log(this.tableData)
        }
      })
    },

    goInHospitalBtn(rrId,hrId){
      this.goInHospitalForm=true
      this.inpatientInfo.rrId=rrId
      this.inpatientInfo.hrId=hrId
    },

    saveGoInHospital(){
      this.$axios.post('api/request/saveGoInHospital',this.inpatientInfo).then(resp=>{
        if(resp.data.code==200){
          this.goInHospitalForm=false
          this.queryInpatientRequestBtn()
          this.$message({
                showClose: true,
                message: '办理入院成功',
                type: 'success'
         });
        }
        
      })
      
    },


    //下一页方法
    nextPage(val){
                    //回调参数val,val等于当前页码
                    this.pageNum=val
                    this.queryInpatientRequestBtn()
    },
    //上一页方法
    prevPage(val){
                    //回调参数val,val等于当前页码
                    this.pageNum=val
                    this.queryInpatientRequestBtn()
    },
    changePage(val){
                    this.pageNum=val
                    this.queryInpatientRequestBtn()
    },
    changeSize(val){
                    this.pageSize=val
                    this.pageNum=1
                    this.queryInpatientRequestBtn()
    },
    resetForm(){
        this.param.staffId=''
        this.param.patientName=''
        this.param.departmentId=''
        this.param.radio=''
        this.valuedate=''
      },

  },

  created(){
        this.queryInpatientStaff(),
        this.queryInpatientDepartment(),
        this.queryInpatientRequestBtn(),
        this.queryAllBed()
  }
}
</script>

<style scoped>

</style>